#https://s.threatbook.com/search?query=2ce72dd8b1615fe36605784c1ae9c444&type=md5
import requests
from bs4 import BeautifulSoup
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4146.4 Safari/537.36'
    }
def trage_search(md5,headers=headers):

    res = requests.get('https://tria.ge/s?q='+md5,headers=headers)
    #print(res.text)
    if "No reports found." in res.text:
        print("No reports found.")
        return False
    else:
        print("Reports found.")
        # 解析网页内容
        soup = BeautifulSoup(res.text, 'html.parser')

        # 查找指定的 a 标签
        a_tag = soup.find('a', class_='row alert')
        # 获取 href 属性的值
        if a_tag:
            href_value = a_tag.get('href')
            return href_value
        else:
            return False

def trage_result(md5):
    title_url = trage_search(md5,headers=headers)
    if title_url == False:
        f = open("trage.html", "w")
        f.write("")
        f.close()
    else:
        #print(title_url)
        newres = requests.get("https://tria.ge/"+title_url+"/behavioral1",headers=headers)
        #print(newres.text)
        # 解析网页内容
        soup = BeautifulSoup(newres.text, 'html.parser')

        # 查找指定的 div 标签
        div_element = soup.find('div', id='signatures')

        # 获取 div 下的所有内容
        if div_element:
            # 获取 div 的所有 HTML 内容
            all_content = div_element.prettify()  # 美化输出
            f = open("trage.html", "w")
            f.write(str(all_content))
            f.close()
            #print(all_content)
        else:
            print("未找到指定的 div 标签")
